/* 
 * File:   cText.cpp
 * Author: gans
 * 
 * Created on 3 Май 2011 г., 2:05
 */

#include "cText.h"

cText::cText(int l) {
    this->length = l;
    strptr = new char*[getLength()];
    dPos = 0;
}

cText::cText(const cText& orig) {
}

void cText::setLength(int l) {
    this->length = l;
}

int cText::getLength() {
    return this->length;
}

void cText::addString(char* s) {
    if (strptr) {
        if (dPos < getLength()) {
            strptr[dPos] = s;
            dPos++;
        }
    }
}

char *cText::returnLastString() {
    return strptr[dPos-1];
}

int cText::deleteString(int nS) {
    if (strptr[nS] != NULL && nS < dPos) {
        
        int i = 0;
        while ( i < dPos - 1) {
            if (i >= nS) {
                strptr[i] = strptr[i+1];
            }
            i++;
        }        
        dPos--;
        return 0;
    } 
    else
        return -1;
}

void cText::printText() {
    for (int i = 0; i < dPos; i++)
        std::cout << strptr[i] << std::endl;
}

cText::~cText() {
    delete [] strptr;
}

